# -*- coding: utf-8 -*-
import scrapy
from autopjt.items import AutopjtItem
from scrapy.http import Request 

class AutospdSpider(scrapy.Spider):
    name = 'autospd'
    allowed_domains = ['dangdang.com']
    start_urls = ['http://category.dangdang.com/cid4008123.html']

    def parse(self, response):
        item = AutopjtItem()
        print("******开始抓网页******")
        #print(item)
        item["name"] = response.xpath("//a[@class='pic']/@title").extract()
        item["price"] = response.xpath("//span[@class='price_n']/text()").extract()
        item["link"] = response.xpath("//a[@class='pic']/@href").extract()
        item["comnum"] = response.xpath("//a[@name='itemlist-review']/text()").extract()
        print("********输出item=*******")
        #print(item)
        yield item
        for i in range(1,10):
            print("******number*****")
            print(i)
            url = "http://category.dangdang.com/pg"+str(i)+"-cid4008123.html"
            yield Request(url,callback=self.parse)


#http://category.dangdang.com/cid4008123.html
#http://category.dangdang.com/pg2-cid4008123.html
#http://category.dangdang.com/pg3-cid4008123.html